package gang.org.springframework.framework.util;

import gang.org.springframework.framework.factory.GangListableBeanFactory;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author gang.chen
 * @description
 * @Date 2021/8/13 12:57
 */
public class GangBeanFactoryUtils {

    /**
     * 业务意义？
     * TODO
     * @return String
     * */
    public static String transformedBeanName(String name){
        return name;
    }

    /**
     * 业务意义？
     * TODO
     * @return  boolean
     * */
    public static boolean isFactoryDereference(String name){
        return false;
    }

    /**
     * @param listableBeanFactory 工厂BeanFactory
     * @param type 任意类（BeanDefinition中匹配该类的BeanDefintion名称）
     * */
    public static String[] beanNamesForTypeIncludingAncestors(GangListableBeanFactory listableBeanFactory,
                                                              Class<?> type,
                                                              boolean includeNonSingeltons,
                                                              boolean allowEagerInit){

        String[] result = listableBeanFactory.getBeanNamesForType(type, includeNonSingeltons, allowEagerInit);
        if(false){
            //TODO
        }
        return result;
    }

    public static<T> Map<String, T> beansOfTypeIncludingAncestors(GangListableBeanFactory lbf,
                                                                  Class<T> type,
                                                                  boolean includeNonSingletons,
                                                                  boolean allowEagerInit){



        Map<String, T> result = new LinkedHashMap<>(4);

        Map<String, T> beansOfType = lbf.getBeansOfType(type, includeNonSingletons, allowEagerInit);

        result.putAll(beansOfType);

        //if TODO
        return result;
    }
}
